package top.codedance.iotp.server.net.handle.subhandle.controller.http.sync;

import com.alibaba.fastjson.JSONObject;
import top.codedance.iotp.server.ServerApplication;
import top.codedance.iotp.server.net.handle.subhandle.controller.AdapterController;
import top.codedance.iotp.server.net.handle.util.DeviceService;

public class DeviceDeleteController extends AdapterController {

    public String doSubHandler(JSONObject body) {
        try {
            if (!adminVerification()) {
                return response403("No access");
            }
            String id = body.getString("id");
            DeviceService.delete(Integer.parseInt(id));
            ServerApplication.initDeviciesCache();
            return okResponse("Delete success");
        } catch (Exception e) {
            return response500("Programe exception");
        }
    }
}
